<template>
	<scroll ref="mescrollRef" @init="mescrollInit" :down="downOption"  @down="downCallback" :up="upOption" @up="upCallback" @emptyclick="emptyClick">
		<stop isBack>
			<view slot="content">保养任务</view>
		</stop>
		<view class="bcf padlr3 padtb2 bdtso">
			<search class="fs8 tac" placeholder=" 单号 \ 物资名称 \ 编码 \ 型号"  v-model="search" @search="doSearch()"></search>
		</view>
		<view class="padlr3 padb2">
			<view class="bcf pos-r mart3  round3 shadow"   @tap.stop="mySlide(index)"
			v-for="(planlistItem,index) in data" :key="planlistItem.id">
				<view class="pos-r ofh round3">
					<view class="bdso pad2" >
						<view class="bcf">
							<plan-list :item="planlistItem"></plan-list>
						</view>
						<view class="bc13 mart2 pad2">
							<machine-item class="w100" :item="planlistItem.machine"></machine-item>
						</view>
					</view>
					<ripple></ripple>
					<sslide ref="mySlideBox">
						<view class="bg-orange flex-c flex-fill pad2 round3">
							<view class="flex1 flcc pad5 pos-r" @tap="startIt(planlistItem.sn)">
								开始保养
								<ripple></ripple>
							</view>
						</view>
					</sslide>
				</view>
			</view>
		</view>
		<loading :loading="myIsLoading"></loading>
	</scroll>
</template>

<script>
	import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
	import List from '../../assets/js/list.js'
	
	import planList from '../../templete/machine/machine_plan_maintain_list_item.vue'
	import machineItem from '../../templete/machine/machine_item.vue'
	
	export default {
		mixins:[MescrollMixin],
		components:{planList,machineItem},
		data() {
			let list = new List()
			return {
				list,
				where:{
					eq:{
						status:'',
						emergency:'',
						level:'',
					}
				},
				search:"",
				data:[]
			}
		},
		methods: {
			reload(){
				this.showLoading()
				this.data=[]
				this.list.setData({_order:{id:"DESC"},_where:this.where,_search:this.search}).reload()
			},
			doSearch(){
				this.showLoading()
				this.data=[]
				this.list.setData({_order:{id:"DESC"},_where:this.where,_search:this.search}).reload()
			},
			startIt(sn){
				this.showLoading()
				this.$api.get('/api/start/machineMaintainOrders',{sn},res=>{
					this.clearLoading()
					this.log(res)
					if(res.s == 1){
						setTimeout(()=>{this.goto('/pages/machi_maintain/maintain_do?id=' + res.d.id)},500)
					}else{
						this.$com.showToast(res.i)
					}
				})
			}
		},
		mounted() {
			this.list.initMescroll(this).setUrl('/api/machineMaintainPlanLists').setData({
				_order:{id:"DESC"},
				_where:this.where,
				_search:this.search,
			}).setCbFunc(res=>{
				this.data = res
				this.clearLoading()
			}).reload()
		},
		onShow() {
			this.log("onshow")
			this.showLoading()
			this.list.reload()
		},
		watch:{
		}
	}
</script>

<style>

</style>
